package net.pulseproject.router.systemtest;

import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;

import net.pulseproject.commons.test.Util;
import net.pulseproject.router.config.parser.LineConfig;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LineConfigTransformer {

	private static final Log LOG = LogFactory.getLog(LineConfigTransformer.class);
	
	public final String transform(final Collection<LineConfig> configs) {
		LOG.debug("transform(configs.size=" + configs.size() + ")");
		
		final Collection<String> lines = new LinkedHashSet<String>();
		for (final LineConfig config : configs) {
			final String line = this.transform(config);
			lines.add(line);
		}
		return Util.join(lines, "\n");
	}
	
	public final String transform(final LineConfig config) {
		LOG.debug("transform(config=" + config + ")");
		
		return Util.join(Arrays.asList(
			config.getId(),
			config.getType(),
			Util.join(config.getOutgoingIds(), ", "),
			Util.join(config.getProperties())
		), " | ");
	}
	
	
}
